package com.example.mongodb.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : zhayh
 * @date : 2021-5-8 16:35
 * @description :
 */

@Configuration
public class DataQueueConfig {
    // 创建直连交换机
    @Bean
    public DirectExchange restaurantExchange() {
        return new DirectExchange("exchange.restaurant");
    }

    // 1. 队列1：创建mongodb的餐厅数据
    @Bean
    public Queue restaurantCreateQueue() {
        return new Queue("queue.restaurant.create");
    }

    // 2. 队列2：更新mongodb的餐厅数据
    @Bean
    public Queue restaurantUpdateQueue() {
        return new Queue("queue.restaurant.update");
    }

    //. 3. 队列3： 删除mongodb的餐厅数据
    @Bean
    public Queue restaurantDeleteQueue() {
        return new Queue("queue.restaurant.delete");
    }

    @Bean
    public Binding bindingRestaurantCreateToOrderExchange() {
        return BindingBuilder.bind(restaurantCreateQueue())
                .to(restaurantExchange())
                .with("restaurant-create");
    }

    @Bean
    public Binding bindingRestaurantUpdateToOrderExchange() {
        return BindingBuilder.bind(restaurantUpdateQueue())
                .to(restaurantExchange())
                .with("restaurant-update");
    }

    @Bean
    public Binding bindingRestaurantDeleteToOrderExchange() {
        return BindingBuilder.bind(restaurantDeleteQueue())
                .to(restaurantExchange())
                .with("restaurant-delete");
    }
}
